package com.example.edu_service.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.commonutils.R;
import com.example.edu_service.entity.EduCourse;
import com.example.edu_service.entity.EduTeacher;
import com.example.edu_service.service.EduCourseService;
import com.example.edu_service.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LUOXIN
 * @create 2021-09-13 21:56
 */

@RestController
@RequestMapping("/edu_service/indexfront")
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    @GetMapping("index")
    public R index(){

        QueryWrapper<EduCourse> coursewrapper = new QueryWrapper<>();
        coursewrapper.orderByDesc("view_count");
        coursewrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(coursewrapper);

        QueryWrapper<EduTeacher> teacherwrapper = new QueryWrapper<>();
        teacherwrapper.orderByDesc("id");
        teacherwrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherwrapper);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }

}
